package com.mx.tool.form.window.qr;

import cn.hutool.extra.qrcode.QrCodeUtil;
import com.mx.tool.util.NotifyUtil;
import org.apache.commons.lang3.StringUtils;

import javax.swing.*;
import java.awt.image.BufferedImage;

/**
 * @Author: 徐建鹏.
 * @create: 2021-11-10 18:38
 * @Description:
 */
public class QrCreateWindow {

    private JPanel jPanel;
    private JTextArea textArea;
    private JButton createButton;
    private JLabel jLabel;

    public JPanel getContent() {
        return jPanel;
    }

    public QrCreateWindow() {
        createButton.addActionListener(e -> {
            String qrContent = textArea.getText();
            if (StringUtils.isBlank(qrContent)) {
                NotifyUtil.error("请输入二维码内容");
                return;
            }
            ImageIcon imageIcon = new ImageIcon();
            BufferedImage bufferedImage = QrCodeUtil.generate(qrContent, 500, 500);
            imageIcon.setImage(bufferedImage);
            jLabel.setIcon(imageIcon);
        });
    }
}
